package com.kjcxlab.avcviewer.network;

import com.kjcxlab.avcviewer.util.Logger;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.util.Enumeration;

/**
 * Created by eshixia on 8/13/2015.
 */
public class NetworkUtil {
    public static void getInterfaces() {
        Enumeration<NetworkInterface> interfaces = null;
        try {
            interfaces = NetworkInterface.getNetworkInterfaces();
        } catch (SocketException e) {
            Logger.d(e.toString());
        }

        while(interfaces != null && interfaces.hasMoreElements()) {
            NetworkInterface anInterface = interfaces.nextElement();
            Logger.d("Found network interface " + anInterface.getName());

            Enumeration<InetAddress> inetAdresses = anInterface.getInetAddresses();

            for (InetAddress inetAddress : Collections.list(inetAdresses)) {
                Logger.d("Interface " + anInterface.getName()
                        + " address: " + inetAddress.toString());
            }
        }
    }
}
